package za.ac.wits.elen7045.persistence.util;

import java.util.Collection;
import java.util.List;

public abstract class ValidationUtilities {
	
	public static boolean isNull(Object obj, String name) {
		return obj == null;
	}
	
	public static boolean isNotNull(Object obj, String name) {
		return obj != null;
	}
	
	public static void ensureNull(Object obj, String name) {
		if (obj != null) {
			throw new RuntimeException(name +" must be null!");
		}
	}
	
	public static void ensureNotNull(Object obj, String name) {
		if (obj == null) {
			throw new RuntimeException(name +" cannot be null!");
		}
	}
	
	public static void ensureNullOrEmpty(Object obj, String name) {
		if (isNotNull(obj, name) && !((String) obj).isEmpty()) {
			throw new RuntimeException(name +" must be null or empty!");
		}
	}
	
	public static void ensureNullOrEmpty(Collection<?> collection, String name) {
		if (isNotNull(collection, name) && collection.size() > 0) {
			throw new RuntimeException(name +" must be null or empty!");
		}
	}
	
	public static void ensureNotNullAndNotEmpty(Object obj, String name) {
		ensureNotNull(obj, name);
		if (obj instanceof String) {
			if (((String) obj).isEmpty()) {
				throw new RuntimeException(name +" cannot be empty!");
			}
		}
		if (obj == null) {
			throw new RuntimeException(name +" cannot be null!");
		}
	}
	
	public static void ensureNotNullAndNotEmpty(Collection<?> collection, String name) {
		ensureNotNull(collection, name);
		if (collection.size() == 0) {
			throw new RuntimeException(name +" cannot be empty!");
		}
	}
	
	public static boolean isEqual(String str1, String str2) {
		if (str1 == null && str2 == null) {
			return true;
		} else if (str1 == null || str2 == null) {
			return false;
		} else {
			return str1.equals(str2);
		}
	}

}
